<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="论文标题" prop="paperTitle">
        <el-input
          v-model="queryParams.paperTitle"
          placeholder="请输入论文标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="论文语言" prop="paperLanguage">
        <el-input
          v-model="queryParams.paperLanguage"
          placeholder="请输入论文语言"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="论文pdf链接" prop="paperLink">
        <el-input
          v-model="queryParams.paperLink"
          placeholder="请输入论文pdf链接"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="关联模型" prop="model">
        <el-input
          v-model="queryParams.model"
          placeholder="请输入关联模型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发表日期" prop="publicationDate">
        <el-date-picker clearable
          v-model="queryParams.publicationDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择发表日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="论文分类" prop="paperType">
        <el-input
          v-model="queryParams.paperType"
          placeholder="请输入论文分类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="期刊名称" prop="journalName">
        <el-input
          v-model="queryParams.journalName"
          placeholder="请输入期刊名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="会议名称" prop="conferenceName">
        <el-input
          v-model="queryParams.conferenceName"
          placeholder="请输入会议名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="DOI号" prop="doi">
        <el-input
          v-model="queryParams.doi"
          placeholder="请输入DOI号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="研究领域" prop="researchField">
        <el-input
          v-model="queryParams.researchField"
          placeholder="请输入研究领域"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="文章类型" prop="articleType">
        <el-input
          v-model="queryParams.articleType"
          placeholder="请输入文章类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="通讯作者" prop="correspondingAuthor">
        <el-input
          v-model="queryParams.correspondingAuthor"
          placeholder="请输入通讯作者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="引用次数" prop="citationCount">
        <el-input
          v-model="queryParams.citationCount"
          placeholder="请输入引用次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="在线链接" prop="onlineLink">
        <el-input
          v-model="queryParams.onlineLink"
          placeholder="请输入在线链接"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:paper:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:paper:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:paper:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:paper:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="paperList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="论文主键" align="center" prop="paperId" show-overflow-tooltip="true"/>
      <el-table-column label="论文标题" align="center" prop="paperTitle" show-overflow-tooltip="true"/>
      <el-table-column label="论文作者" align="center" prop="paperAuthors" show-overflow-tooltip="true"/>
      <el-table-column label="论文图片" align="center" prop="paperImage" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.paperImage" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="论文图片" align="center" prop="paperImage" show-overflow-tooltip="true"/>
      <el-table-column label="论文语言" align="center" prop="paperLanguage" show-overflow-tooltip="true"/>
      <el-table-column label="摘要" align="center" prop="paperAbstract" show-overflow-tooltip="true"/>
      <el-table-column label="关键字" align="center" prop="paperKeywords" show-overflow-tooltip="true"/>
      <el-table-column label="论文pdf链接" align="center" prop="paperLink" />
      <el-table-column label="关联模型" align="center" prop="model" />
      <el-table-column label="发表日期" align="center" prop="publicationDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.publicationDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="论文分类" align="center" prop="paperType" />
      <el-table-column label="期刊名称" align="center" prop="journalName" />
      <el-table-column label="会议名称" align="center" prop="conferenceName" />
      <el-table-column label="引用" align="center" prop="citation" />
      <el-table-column label="DOI号" align="center" prop="doi" />
      <el-table-column label="研究领域" align="center" prop="researchField" />
      <el-table-column label="文章类型" align="center" prop="articleType" />
      <el-table-column label="基金支持" align="center" prop="funding" />
      <el-table-column label="作者单位" align="center" prop="authorAffiliations" />
      <el-table-column label="通讯作者" align="center" prop="correspondingAuthor" />
      <el-table-column label="引用次数" align="center" prop="citationCount" />
      <el-table-column label="在线链接" align="center" prop="onlineLink" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:paper:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:paper:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改论文管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="论文标题" prop="paperTitle">
          <el-input v-model="form.paperTitle" placeholder="请输入论文标题" />
        </el-form-item>
        <el-form-item label="论文作者" prop="paperAuthors">
          <el-input v-model="form.paperAuthors" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="论文图片" prop="paperImage">
          <image-upload v-model="form.paperImage"/>
        </el-form-item>
        <el-form-item label="论文图片" prop="paperImage">
          <el-input v-model="form.paperImage" type="textarea" placeholder="请输入论文图片" />
        </el-form-item>
        <el-form-item label="论文语言" prop="paperLanguage">
          <el-input v-model="form.paperLanguage" placeholder="请输入论文语言" />
        </el-form-item>
        <el-form-item label="摘要" prop="paperAbstract">
          <el-input v-model="form.paperAbstract" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="关键字" prop="paperKeywords">
          <el-input v-model="form.paperKeywords" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="论文pdf链接" prop="paperLink">
          <el-input v-model="form.paperLink" placeholder="请输入论文pdf链接" />
        </el-form-item>
        <el-form-item label="关联模型" prop="model">
          <el-input v-model="form.model" placeholder="请输入关联模型" />
        </el-form-item>
        <el-form-item label="发表日期" prop="publicationDate">
          <el-date-picker clearable
            v-model="form.publicationDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择发表日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="论文分类" prop="paperType">
          <el-input v-model="form.paperType" placeholder="请输入论文分类" />
        </el-form-item>
        <el-form-item label="期刊名称" prop="journalName">
          <el-input v-model="form.journalName" placeholder="请输入期刊名称" />
        </el-form-item>
        <el-form-item label="会议名称" prop="conferenceName">
          <el-input v-model="form.conferenceName" placeholder="请输入会议名称" />
        </el-form-item>
        <el-form-item label="引用" prop="citation">
          <el-input v-model="form.citation" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="DOI号" prop="doi">
          <el-input v-model="form.doi" placeholder="请输入DOI号" />
        </el-form-item>
        <el-form-item label="研究领域" prop="researchField">
          <el-input v-model="form.researchField" placeholder="请输入研究领域" />
        </el-form-item>
        <el-form-item label="文章类型" prop="articleType">
          <el-input v-model="form.articleType" placeholder="请输入文章类型" />
        </el-form-item>
        <el-form-item label="基金支持" prop="funding">
          <el-input v-model="form.funding" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="作者单位" prop="authorAffiliations">
          <el-input v-model="form.authorAffiliations" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="通讯作者" prop="correspondingAuthor">
          <el-input v-model="form.correspondingAuthor" placeholder="请输入通讯作者" />
        </el-form-item>
        <el-form-item label="引用次数" prop="citationCount">
          <el-input v-model="form.citationCount" placeholder="请输入引用次数" />
        </el-form-item>
        <el-form-item label="在线链接" prop="onlineLink">
          <el-input v-model="form.onlineLink" placeholder="请输入在线链接" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPaper, getPaper, delPaper, addPaper, updatePaper } from "@/api/system/paper";

export default {
  name: "Paper",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 论文管理表格数据
      paperList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        paperTitle: null,
        paperAuthors: null,
        paperImage: null,
        paperLanguage: null,
        paperAbstract: null,
        paperKeywords: null,
        paperLink: null,
        model: null,
        publicationDate: null,
        paperType: null,
        journalName: null,
        conferenceName: null,
        citation: null,
        doi: null,
        researchField: null,
        articleType: null,
        funding: null,
        authorAffiliations: null,
        correspondingAuthor: null,
        citationCount: null,
        onlineLink: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询论文管理列表 */
    getList() {
      this.loading = true;
      listPaper(this.queryParams).then(response => {
        this.paperList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        paperId: null,
        paperTitle: null,
        paperAuthors: null,
        paperImage: null,
        paperLanguage: null,
        paperAbstract: null,
        paperKeywords: null,
        paperLink: null,
        model: null,
        publicationDate: null,
        paperType: null,
        journalName: null,
        conferenceName: null,
        citation: null,
        doi: null,
        researchField: null,
        articleType: null,
        funding: null,
        authorAffiliations: null,
        correspondingAuthor: null,
        citationCount: null,
        onlineLink: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.paperId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加论文管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const paperId = row.paperId || this.ids
      getPaper(paperId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改论文管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.paperId != null) {
            updatePaper(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPaper(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const paperIds = row.paperId || this.ids;
      this.$modal.confirm('是否确认删除论文管理编号为"' + paperIds + '"的数据项？').then(function() {
        return delPaper(paperIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/paper/export', {
        ...this.queryParams
      }, `paper_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
